<?php

/**
 * Camioneta filter form base class.
 *
 * @package    cronos-doctrine
 * @subpackage filter
 * @author     Your name here
 * @version    SVN: $Id: sfDoctrineFormFilterGeneratedTemplate.php 29570 2010-05-21 14:49:47Z Kris.Wallsmith $
 */
abstract class BaseCamionetaFormFilter extends BaseFormFilterDoctrine
{
  public function setup()
  {
    $this->setWidgets(array(
      'empresa_id'          => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'area_id'             => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('Area'), 'add_empty' => true)),
      'operador_id'         => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('Operador'), 'add_empty' => true)),
      'ayudante_id'         => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('Ayudante'), 'add_empty' => true)),
      'nombre'              => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'placa'               => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'marca'               => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'modelo'              => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'anio'                => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'serie'               => new sfWidgetFormFilterInput(),
      'telefono'            => new sfWidgetFormFilterInput(),
      'seguro'              => new sfWidgetFormFilterInput(),
      'seguro_telefono'     => new sfWidgetFormFilterInput(),
      'seguro_vencimiento'  => new sfWidgetFormFilterDate(array('from_date' => new sfWidgetFormDate(), 'to_date' => new sfWidgetFormDate())),
      'status'              => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'is_franquicia'       => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'fecha_verificacion'  => new sfWidgetFormFilterDate(array('from_date' => new sfWidgetFormDate(), 'to_date' => new sfWidgetFormDate())),
      'fecha_mantenimiento' => new sfWidgetFormFilterDate(array('from_date' => new sfWidgetFormDate(), 'to_date' => new sfWidgetFormDate())),
      'alerta_kilometraje'  => new sfWidgetFormFilterInput(),
      'created_at'          => new sfWidgetFormFilterDate(array('from_date' => new sfWidgetFormDate(), 'to_date' => new sfWidgetFormDate(), 'with_empty' => false)),
      'updated_at'          => new sfWidgetFormFilterDate(array('from_date' => new sfWidgetFormDate(), 'to_date' => new sfWidgetFormDate(), 'with_empty' => false)),
      'categoria_list'      => new sfWidgetFormDoctrineChoice(array('multiple' => true, 'model' => 'Categoria')),
    ));

    $this->setValidators(array(
      'empresa_id'          => new sfValidatorSchemaFilter('text', new sfValidatorInteger(array('required' => false))),
      'area_id'             => new sfValidatorDoctrineChoice(array('required' => false, 'model' => $this->getRelatedModelName('Area'), 'column' => 'id')),
      'operador_id'         => new sfValidatorDoctrineChoice(array('required' => false, 'model' => $this->getRelatedModelName('Operador'), 'column' => 'id')),
      'ayudante_id'         => new sfValidatorDoctrineChoice(array('required' => false, 'model' => $this->getRelatedModelName('Ayudante'), 'column' => 'id')),
      'nombre'              => new sfValidatorPass(array('required' => false)),
      'placa'               => new sfValidatorPass(array('required' => false)),
      'marca'               => new sfValidatorPass(array('required' => false)),
      'modelo'              => new sfValidatorPass(array('required' => false)),
      'anio'                => new sfValidatorPass(array('required' => false)),
      'serie'               => new sfValidatorPass(array('required' => false)),
      'telefono'            => new sfValidatorPass(array('required' => false)),
      'seguro'              => new sfValidatorPass(array('required' => false)),
      'seguro_telefono'     => new sfValidatorPass(array('required' => false)),
      'seguro_vencimiento'  => new sfValidatorDateRange(array('required' => false, 'from_date' => new sfValidatorDate(array('required' => false)), 'to_date' => new sfValidatorDateTime(array('required' => false)))),
      'status'              => new sfValidatorSchemaFilter('text', new sfValidatorInteger(array('required' => false))),
      'is_franquicia'       => new sfValidatorSchemaFilter('text', new sfValidatorInteger(array('required' => false))),
      'fecha_verificacion'  => new sfValidatorDateRange(array('required' => false, 'from_date' => new sfValidatorDate(array('required' => false)), 'to_date' => new sfValidatorDateTime(array('required' => false)))),
      'fecha_mantenimiento' => new sfValidatorDateRange(array('required' => false, 'from_date' => new sfValidatorDate(array('required' => false)), 'to_date' => new sfValidatorDateTime(array('required' => false)))),
      'alerta_kilometraje'  => new sfValidatorSchemaFilter('text', new sfValidatorInteger(array('required' => false))),
      'created_at'          => new sfValidatorDateRange(array('required' => false, 'from_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 00:00:00')), 'to_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 23:59:59')))),
      'updated_at'          => new sfValidatorDateRange(array('required' => false, 'from_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 00:00:00')), 'to_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 23:59:59')))),
      'categoria_list'      => new sfValidatorDoctrineChoice(array('multiple' => true, 'model' => 'Categoria', 'required' => false)),
    ));

    $this->widgetSchema->setNameFormat('camioneta_filters[%s]');

    $this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);

    $this->setupInheritance();

    parent::setup();
  }

  public function addCategoriaListColumnQuery(Doctrine_Query $query, $field, $values)
  {
    if (!is_array($values))
    {
      $values = array($values);
    }

    if (!count($values))
    {
      return;
    }

    $query
      ->leftJoin($query->getRootAlias().'.CamionetaHasCategoria CamionetaHasCategoria')
      ->andWhereIn('CamionetaHasCategoria.categoria_id', $values)
    ;
  }

  public function getModelName()
  {
    return 'Camioneta';
  }

  public function getFields()
  {
    return array(
      'id'                  => 'Number',
      'empresa_id'          => 'Number',
      'area_id'             => 'ForeignKey',
      'operador_id'         => 'ForeignKey',
      'ayudante_id'         => 'ForeignKey',
      'nombre'              => 'Text',
      'placa'               => 'Text',
      'marca'               => 'Text',
      'modelo'              => 'Text',
      'anio'                => 'Text',
      'serie'               => 'Text',
      'telefono'            => 'Text',
      'seguro'              => 'Text',
      'seguro_telefono'     => 'Text',
      'seguro_vencimiento'  => 'Date',
      'status'              => 'Number',
      'is_franquicia'       => 'Number',
      'fecha_verificacion'  => 'Date',
      'fecha_mantenimiento' => 'Date',
      'alerta_kilometraje'  => 'Number',
      'created_at'          => 'Date',
      'updated_at'          => 'Date',
      'categoria_list'      => 'ManyKey',
    );
  }
}
